package com.dst.controller;

import com.dst.eneity.Category;
import com.dst.service.impl.CategoryServiceImpl;
import com.dst.service.impl.TeaServiceImpl;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/category")
public class CategoryController {
@RequestMapping("/selectAll")
    public String selectAll(Model model){
    CategoryServiceImpl categoryService = new CategoryServiceImpl();
    List<Category> categories = categoryService.selectAll();
    model.addAttribute("categories",categories);
    return "/addTea.jsp";
}
    @RequestMapping("/selectCategory")
    public String selectCategory(Model model){
        CategoryServiceImpl categoryService = new CategoryServiceImpl();
        List<Category> cates = categoryService.selectCategory();
        model.addAttribute("cates",cates);
        return "/categorylist.jsp";
    }
    @RequestMapping("/delete")
    public String delete(int id){
        TeaServiceImpl teaService = new TeaServiceImpl();
        teaService.deleteCateAndTea(id);
        CategoryServiceImpl categoryService = new CategoryServiceImpl();
        categoryService.delete(id);
        return "redirect:/category/selectCategory.do";
    }
}
